package cc.uncarbon.module.appapi.web.app;

import cc.uncarbon.framework.web.model.response.ApiResult;
import cc.uncarbon.module.appapi.constant.AppApiConstant;
import cc.uncarbon.module.appapi.model.vo.ItemAccountVo;
import cc.uncarbon.module.appapi.model.vo.ItemVO;
import cc.uncarbon.module.appapi.service.ItemService;
import cc.uncarbon.module.appapi.service.UserCouponService;
import com.yanrumiao.entity.ItemEntity;
import com.yanrumiao.entity.UserCouponEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "小程序项目管理")
@RequestMapping(AppApiConstant.HTTP_API_URL_PREFIX + "/api/v1")
@RequiredArgsConstructor
@RestController
@Slf4j
public class ItemController {

    private final ItemService itemService;
    private final UserCouponService userCouponService;

    @Operation(summary = "项目详情")
    @GetMapping("/item/{id}")
    public ApiResult<ItemVO> getItemInfo(@PathVariable("id") Long id) {
        return ApiResult.data(itemService.getOneByIdAndBanner(id));
    }
    @Operation(summary = "项目结算")
    @GetMapping("/item/account/{id}")
    public  ApiResult<ItemAccountVo> getItemCount(@PathVariable("id") Long id){

        ItemAccountVo itemAccountVo = new ItemAccountVo();
        ItemEntity itemEntity = itemService.getOneById(id);
        List<UserCouponEntity> couponList = userCouponService.getCouponByUserId();
        itemAccountVo.setItemInfo(itemEntity);
        itemAccountVo.setCouponList(couponList);
        return ApiResult.data(itemAccountVo);
    }
}
